package cn.xmoit.other;

import com.theokanning.openai.OpenAiService;
import com.theokanning.openai.completion.CompletionRequest;

import java.time.Duration;
import java.util.Arrays;

public class ChatGptTest {

	public static void main(String[] args) {
		String token = "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";
		// 构建openai api对象，由于处理时间比较长，建议设置一个合理的超时时间
		OpenAiService service = new OpenAiService(token, Duration.ofSeconds(60));
		CompletionRequest completionRequest = CompletionRequest.builder()
			.prompt("请用java实现1到100的求和？")
			.model("text-davinci-003")
			.temperature(0.9d)
			.maxTokens(1024)
			.stop(Arrays.asList("Human:", "AI:"))
			.echo(true)
			.build();
		service.createCompletion(completionRequest).getChoices().forEach(System.out::println);
	}

}
